local feijun = fk.CreateSkill{
  name = "mod__feijun",
}
local feijun_ = {
  anim_type = "control",
  card_num = 1,
  target_num = 1,
  prompt = "#mod__feijun",
  can_use = function (self, player)
    return (player:getMark("feijun_1-phase") == 0 or player:getMark("feijun_2-phase") == 0) and not player:isNude() 
  end,
  card_filter = function(self, player, to_select, selected)
    return #selected == 0 and not player:prohibitDiscard(Fk:getCardById(to_select))
  end,
  target_filter = function(self, player, to_select, selected, selected_cards)
    local p = Fk:currentRoom():getPlayerById(to_select)
    return #selected == 0 and p ~= Self and 
    ((player:getMark("feijun_1-phase") == 0 and p:getHandcardNum() >= player:getHandcardNum() and not p:isKongcheng()) or 
    (player:getMark("feijun_2-phase") == 0 and #p:getCardIds("e") >= #player:getCardIds("e") and #p:getCardIds("e") > 0))
  end,
  on_use = function(self, room, effect)
    local player = effect.from
    local target = effect.tos[1]
    room:throwCard(effect.cards, self.name, player, player)
    if player.dead then return end
    local choices = {}
    if target:getHandcardNum() >= player:getHandcardNum() and not target:isKongcheng() and player:getMark("feijun_1-phase") == 0 then
      table.insert(choices, "mod__feijun1")
    end
    if #target:getCardIds("e") >= #player:getCardIds("e") and #target:getCardIds("e") > 0 and player:getMark("feijun_2-phase") == 0 then
      table.insert(choices, "mod__feijun2")
    end
    local choice = room:askForChoice(player, choices, self.name, "#mod__feijun-choice::"..target.id)
    if choice == "mod__feijun1" then
      local card = room:askForCard(target, 1, 1, true, self.name, false, ".", "#mod__feijun-give:"..player.id)
      room:obtainCard(player, card[1], false, fk.ReasonGive)
      room:addPlayerMark(player, "feijun_1-phase", 1)
    else
      room:askForDiscard(target, 1, 1, true, self.name, false, ".|.|.|equip", "#mod__feijun-discard")
      room:addPlayerMark(player, "feijun_2-phase", 1)
    end
  end,
}
feijun:addEffect("active", feijun_)
return feijun